package com.welike.shibo.controller;

import com.welike.shibo.eneity.JsonResult;
import com.welike.shibo.service.HomeService;
import com.welike.shibo.service.VideoService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * @author fangyu
 * @version v1.0.0
 * @since 2019/11/24 1:11 上午
 */
@Controller
public class IndexController {

    @Resource
    private HomeService homeService;

    @Resource
    private VideoService videoService;

    @GetMapping(value = {"/", "/index"})
    public String index(){
        return "index";
    }

    @GetMapping(value = {"/home"})
    @ResponseBody
    public JsonResult home(){
        return homeService.sumForAll();
    }

    @GetMapping("/share/{vid}")
    public ModelAndView share(
            Model model,
            @PathVariable String vid
    ) {
        String videoUrl = videoService.queryVideoUrlByVid(vid);
        String title = videoService.queryDescByVid(vid);
        model.addAttribute("videoUrl", videoUrl);
        model.addAttribute("title", title);
        return new ModelAndView("mobile/share");
    }
}